using IQIGame.Onigao.Game;
using IQIGame.Onigao.GamePlay.Data;
using NetProtocol.Enum;

namespace IQIGame.Onigao.GamePlay
{
    /// <summary>
    /// 迷宫小游戏控制器
    /// 包括道具提交等会打开独立界面，且独立界面只在迷宫内出现的功能，不局限于常规意义上理解的小游戏
    /// </summary>
    public class LevelPlayMiniGameCtrl : LevelPlaySubBaseCtrl
    {
        private LevelPlayPushEntityCtrl _pushEntityCtrl;
        private LevelPlayNpcTailingCtrl _npcTailingCtrl;

        #region 生命周期
        public LevelPlayMiniGameCtrl()
        {
            AddSubControllers();
            MsgDispatcher.AddListener<int>(MsgEventType.Level_StartItemSubmit, OnStartItemSubmit);
            MsgDispatcher.AddListener<LevelMiniGameType, int>(MsgEventType.Level_StartMiniGame, OnStartMiniGame);
        }

        private void AddSubControllers()
        {
            _pushEntityCtrl = AddSubController<LevelPlayPushEntityCtrl>();
            _npcTailingCtrl = AddSubController<LevelPlayNpcTailingCtrl>();
        }

        protected override void OnModuleGameplayInit()
        {

        }

        protected override void OnSceneLoaded()
        {

        }

        protected override void OnDispose()
        {
            MsgDispatcher.RemoveListener<int>(MsgEventType.Level_StartItemSubmit, OnStartItemSubmit);
            MsgDispatcher.RemoveListener<LevelMiniGameType, int>(MsgEventType.Level_StartMiniGame, OnStartMiniGame);
            _pushEntityCtrl = null;
            _npcTailingCtrl = null;
        }
        #endregion

        private void OnStartItemSubmit(int cid)
        {
            ManagerCenter.UI.ShowWindow<UISubmitItem>(UD_SubmitItem.Create(cid));
        }

        private void OnStartMiniGame(LevelMiniGameType type, int cid)
        {
            switch (type)
            {
                case LevelMiniGameType.NpcTailing:
                    _npcTailingCtrl.StartTailing(cid).Forget();
                    break;
                default:
                    break;
            }
        }
    }
}
